﻿namespace System.ServiceModel.DomainServices.Client.ApplicationServices
{
    using System;

    public sealed class SaveUserOperation : AuthenticationOperation
    {
        private Action<SaveUserOperation> _completeAction;

        internal SaveUserOperation(AuthenticationService service, Action<SaveUserOperation> completeAction, object userState) : base(service, userState)
        {
            this._completeAction = completeAction;
        }

        protected override IAsyncResult BeginCore(AsyncCallback callback)
        {
            return base.Service.BeginSaveUser(base.Service.User, callback, null);
        }

        protected override void CancelCore()
        {
            base.Service.CancelSaveUser(base.AsyncResult);
        }

        protected override object EndCore(IAsyncResult asyncResult)
        {
            return base.Service.EndSaveUser(asyncResult);
        }

        protected override void InvokeCompleteAction()
        {
            if (this._completeAction != null)
            {
                this._completeAction(this);
            }
        }
    }
}

